using FreshMeat.Xaml;

namespace XamlTest
{
   public class MockModel : ViewModel
   {
      public MockModel(IMockService service)
      {
         var context = new OperationContext();

         // ReSharper disable ConvertToLambdaExpression
         
         AddCommand = new Command(
            () => true,
            () =>
            {
               // Catching exceptions here is the action's responsibility (none here for simplicity)
               service.Add(A, B,
                           (result, error) =>
                           {
                              if (error != null)
                                 Message = error.Message;
                              else
                                 Result = result;
                           });
            },
            context,
            "Add");

         MultiplyCommand = new Command(
            () => true,
            () => service.Multiply(A, B,
                                   (result, error) =>
                                   {
                                      if (error != null)
                                         Message = error.Message;
                                      else
                                         Result = result;
                                   }),
            context,
            "Multiply");

         // ReSharper restore ConvertToLambdaExpression
      }

      public Command AddCommand { get; private set; }

      public Command MultiplyCommand { get; private set; }

      public int A { get; set; }

      public int B { get; set; }

      int result;
      public int Result
      {
         get { return result; }
         set
         {
            result = value;
            Props.Changed(() => Result);
         }
      }

      string message;
      public string Message
      {
         get { return message; }
         set
         {
            message = value;
            Props.Changed(() => Message);
         }
      }
   }
}